package com.second.hand.trading.server.controller;


import com.second.hand.trading.server.domain.Intergral;
import com.second.hand.trading.server.service.IntergralDemoService;
import com.second.hand.trading.server.utils.R;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/intergral")
@RestController
public class IntergralDemoController {
    private final IntergralDemoService intergralService;

    public IntergralDemoController(IntergralDemoService intergralService) {
        this.intergralService = intergralService;
    }

    /**
     * 用户签到加积分
     * @param token
     * @return
     */
    @PostMapping("/incr")
    public R<String> incrIntergral(@RequestHeader("token") String token) {
        intergralService.incrIntergral(token);
        return R.success();
    }

    /**
     * 获取当前登录用户的签到信息
     * @return
     */
    @GetMapping("/get")
    public R<Intergral> getCurrentUserIntergral(@RequestHeader("token") String token){
        return R.success(intergralService.getIntergral(token));
    }

    @PostMapping("/decr")
    public R<?> decrIntergral(@RequestHeader("token") String token, Integer type){
        intergralService.decr(token,type);
        return R.success();
    }
}
